﻿using TjZheng.News.Business;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using TjZheng.Framework;
using TjZheng.Cache;
using TjZheng.News.DataEntity;

namespace TjZheng.News.Process
{
    public static class BadWordHelper
    {
        public static string FilterBadWords(this string text)
        {
            if (text.IsNull())
            {
                return text;
            }

            var objBadWordsArray = GetAllBadWords().ToArray();
            return text.ReplaceBadWords(objBadWordsArray);
        }

        public static bool IsContainsBadWords(this string text)
        {
            var objBadWordsArray = GetAllBadWords().ToArray();
            return text.IsContainsBadWords(objBadWordsArray);
        }

        public static string[] SearchMatchBadWords(this string text, string connectionStringKey = "", string dataObjectParam = "")
        {
            var objBadWordsArray = GetAllBadWords(connectionStringKey, dataObjectParam).ToArray();
            return text.SearchBadWords(objBadWordsArray);
        }

        public static List<string> GetAllBadWords(string connectionStringKey = "", string dataObjectParam = "")
        {
            BizBadWord objBizBadWords = new BizBadWord(connectionStringKey, dataObjectParam);
            return objBizBadWords.GetFieldListCache<string, BadWord, int>("", TimeSpan.FromMinutes(1), "", "Word");
        }
    }
}
